<?php

namespace App\Http\Controllers\Seller;

use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class KefuController extends BaseController
{
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->assign(['menu'=>'kefu']);
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {

        if ($this->isOnSubmit()) {
            $items = $this->request->input('items');
            if ($items) {
                $this->shop->kefus()->whereIn('id', $items)->delete();
            }
            return $this->messager()->render();
        } else {

            $shop  = $this->shop;
            $items = $shop->kefus;
            return $this->view('seller.shop.kefu', compact('shop', 'items'));
        }
    }

    /**
     * @return mixed
     */
    public function qrcode()
    {
        return QrCode::format('png')->size(300)->generate(url('h5/kefu/bind/'.$this->shop->shop_id));
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function toggle()
    {
        $id = $this->request->input('id');
        $available = $this->request->input('available');

        $this->shop->kefus()->find($id)->update(['available'=>$available]);
        return ajaxReturn();
    }
}
